Skip to content

Create radial_basis_function_neural_network #12342

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 13 commits into from
Closed

Create radial_basis_function_neural_network #12342

wants to merge 13 commits into from

Conversation

Swastik0710
Copy link

Implemented the Radial Basis Function Neural Network inside the neural_network folder of the repo. Feel free to tell if it require any changes.

@algorithms-keeper algorithms-keeper bot added the awaiting reviews This PR is ready to be reviewed label Oct 31, 2024
@algorithms-keeper algorithms-keeper bot added require descriptive names This PR needs descriptive function and/or variable names require tests Tests [doctest/unittest/pytest] are required require type hints https://docs.python.org/3/library/typing.html labels Oct 31, 2024
Copy link

@algorithms-keeper algorithms-keeper bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Click here to look at the relevant links ⬇️

🔗 Relevant Links

Repository:

Python:

Automated review generated by algorithms-keeper. If there's any problem regarding this review, please open an issue about it.

algorithms-keeper commands and options

algorithms-keeper actions can be triggered by commenting on this PR:

  • @algorithms-keeper review to trigger the checks for only added pull request files
  • @algorithms-keeper review-all to trigger the checks for all the pull request files, including the modified files. As we cannot post review comments on lines not part of the diff, this command will post all the messages in one comment.

NOTE: Commands are in beta and so this feature is restricted only to a member or owner of the organization.

import numpy as np # For numerical operations

class RBFNN:
def __init__(self, input_size, hidden_size, output_size):

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please provide return type hint for the function: __init__. If the function does not return a value, please provide the type hint as: def function() -> None:

Please provide type hint for the parameter: input_size

Please provide type hint for the parameter: hidden_size

Please provide type hint for the parameter: output_size

# Initialize weights for the output layer
self.weights = np.random.rand(hidden_size, output_size) # Weights for output layer

def rbf(self, x, center, spread):

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As there is no test file in this pull request nor any test function or class in the file neural_network/radial_basis_function_neural_network.py, please provide doctest for the function rbf

Please provide return type hint for the function: rbf. If the function does not return a value, please provide the type hint as: def function() -> None:

Please provide descriptive name for the parameter: x

Please provide type hint for the parameter: x

Please provide type hint for the parameter: center

Please provide type hint for the parameter: spread

""" Radial Basis Function (Gaussian). """
return np.exp(-np.linalg.norm(x - center) ** 2 / (2 * spread ** 2))

def forward(self, x):

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As there is no test file in this pull request nor any test function or class in the file neural_network/radial_basis_function_neural_network.py, please provide doctest for the function forward

Please provide return type hint for the function: forward. If the function does not return a value, please provide the type hint as: def function() -> None:

Please provide descriptive name for the parameter: x

Please provide type hint for the parameter: x

output = np.dot(hidden_outputs, self.weights) # Compute final output
return output

def train(self, X, y, epochs, learning_rate):

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As there is no test file in this pull request nor any test function or class in the file neural_network/radial_basis_function_neural_network.py, please provide doctest for the function train

Please provide return type hint for the function: train. If the function does not return a value, please provide the type hint as: def function() -> None:

Please provide descriptive name for the parameter: X

Please provide type hint for the parameter: X

Please provide descriptive name for the parameter: y

Please provide type hint for the parameter: y

Please provide type hint for the parameter: epochs

Please provide type hint for the parameter: learning_rate

# Update weights
self.weights += learning_rate * hidden_outputs.reshape(-1, 1) * error

def predict(self, X):

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As there is no test file in this pull request nor any test function or class in the file neural_network/radial_basis_function_neural_network.py, please provide doctest for the function predict

Please provide return type hint for the function: predict. If the function does not return a value, please provide the type hint as: def function() -> None:

Please provide descriptive name for the parameter: X

Please provide type hint for the parameter: X

@algorithms-keeper algorithms-keeper bot added the tests are failing Do not merge until tests pass label Oct 31, 2024
Copy link

@algorithms-keeper algorithms-keeper bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Click here to look at the relevant links ⬇️

🔗 Relevant Links

Repository:

Python:

Automated review generated by algorithms-keeper. If there's any problem regarding this review, please open an issue about it.

algorithms-keeper commands and options

algorithms-keeper actions can be triggered by commenting on this PR:

  • @algorithms-keeper review to trigger the checks for only added pull request files
  • @algorithms-keeper review-all to trigger the checks for all the pull request files, including the modified files. As we cannot post review comments on lines not part of the diff, this command will post all the messages in one comment.

NOTE: Commands are in beta and so this feature is restricted only to a member or owner of the organization.

import numpy as np # For numerical operations

class RBFNN:
def __init__(self, input_size, hidden_size, output_size):

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please provide return type hint for the function: __init__. If the function does not return a value, please provide the type hint as: def function() -> None:

Please provide type hint for the parameter: input_size

Please provide type hint for the parameter: hidden_size

Please provide type hint for the parameter: output_size

# Initialize weights for the output layer
self.weights = rng.random((hidden_size, output_size)) # Weights for output layer

def rbf(self, x, center, spread):

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As there is no test file in this pull request nor any test function or class in the file neural_network/radial_basis_function_neural_network.py, please provide doctest for the function rbf

Please provide return type hint for the function: rbf. If the function does not return a value, please provide the type hint as: def function() -> None:

Please provide descriptive name for the parameter: x

Please provide type hint for the parameter: x

Please provide type hint for the parameter: center

Please provide type hint for the parameter: spread

""" Radial Basis Function (Gaussian). """
return np.exp(-np.linalg.norm(x - center) ** 2 / (2 * spread ** 2))

def forward(self, x):

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As there is no test file in this pull request nor any test function or class in the file neural_network/radial_basis_function_neural_network.py, please provide doctest for the function forward

Please provide return type hint for the function: forward. If the function does not return a value, please provide the type hint as: def function() -> None:

Please provide descriptive name for the parameter: x

Please provide type hint for the parameter: x

output = np.dot(hidden_outputs, self.weights) # Compute final output
return output

def train(self, x_train, y_train, epochs, learning_rate):

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As there is no test file in this pull request nor any test function or class in the file neural_network/radial_basis_function_neural_network.py, please provide doctest for the function train

Please provide return type hint for the function: train. If the function does not return a value, please provide the type hint as: def function() -> None:

Please provide type hint for the parameter: x_train

Please provide type hint for the parameter: y_train

Please provide type hint for the parameter: epochs

Please provide type hint for the parameter: learning_rate

# Update weights
self.weights += learning_rate * hidden_outputs.reshape(-1, 1) * error

def predict(self, x_test):

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As there is no test file in this pull request nor any test function or class in the file neural_network/radial_basis_function_neural_network.py, please provide doctest for the function predict

Please provide return type hint for the function: predict. If the function does not return a value, please provide the type hint as: def function() -> None:

Please provide type hint for the parameter: x_test

@algorithms-keeper algorithms-keeper bot removed the tests are failing Do not merge until tests pass label Oct 31, 2024
@algorithms-keeper algorithms-keeper bot added the tests are failing Do not merge until tests pass label Oct 31, 2024
Copy link

@algorithms-keeper algorithms-keeper bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Click here to look at the relevant links ⬇️

🔗 Relevant Links

Repository:

Python:

Automated review generated by algorithms-keeper. If there's any problem regarding this review, please open an issue about it.

algorithms-keeper commands and options

algorithms-keeper actions can be triggered by commenting on this PR:

  • @algorithms-keeper review to trigger the checks for only added pull request files
  • @algorithms-keeper review-all to trigger the checks for all the pull request files, including the modified files. As we cannot post review comments on lines not part of the diff, this command will post all the messages in one comment.

NOTE: Commands are in beta and so this feature is restricted only to a member or owner of the organization.

import numpy as np

class ART1:
def __init__(self, num_features, vigilance=0.8):

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please provide return type hint for the function: __init__. If the function does not return a value, please provide the type hint as: def function() -> None:

Please provide type hint for the parameter: num_features

Please provide type hint for the parameter: vigilance

self.vigilance = vigilance
self.weights = [] # Stores the weights for clusters

def _similarity(self, x, w):

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As there is no test file in this pull request nor any test function or class in the file neural_network/adaptive_resonance_theory_1.py, please provide doctest for the function _similarity

Please provide return type hint for the function: _similarity. If the function does not return a value, please provide the type hint as: def function() -> None:

Please provide descriptive name for the parameter: x

Please provide type hint for the parameter: x

Please provide descriptive name for the parameter: w

Please provide type hint for the parameter: w

"""
return np.sum(np.minimum(x, w)) / np.sum(x)

def _weight_update(self, x, w):

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As there is no test file in this pull request nor any test function or class in the file neural_network/adaptive_resonance_theory_1.py, please provide doctest for the function _weight_update

Please provide return type hint for the function: _weight_update. If the function does not return a value, please provide the type hint as: def function() -> None:

Please provide descriptive name for the parameter: x

Please provide type hint for the parameter: x

Please provide descriptive name for the parameter: w

Please provide type hint for the parameter: w

"""
return np.minimum(x, w)

def train(self, data):

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As there is no test file in this pull request nor any test function or class in the file neural_network/adaptive_resonance_theory_1.py, please provide doctest for the function train

Please provide return type hint for the function: train. If the function does not return a value, please provide the type hint as: def function() -> None:

Please provide type hint for the parameter: data

if not assigned:
self.weights.append(x.copy())

def predict(self, x):

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As there is no test file in this pull request nor any test function or class in the file neural_network/adaptive_resonance_theory_1.py, please provide doctest for the function predict

Please provide return type hint for the function: predict. If the function does not return a value, please provide the type hint as: def function() -> None:

Please provide descriptive name for the parameter: x

Please provide type hint for the parameter: x



class RBFNN:
def __init__(self, input_size, hidden_size, output_size):

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please provide return type hint for the function: __init__. If the function does not return a value, please provide the type hint as: def function() -> None:

Please provide type hint for the parameter: input_size

Please provide type hint for the parameter: hidden_size

Please provide type hint for the parameter: output_size

(hidden_size, output_size)
) # Weights for output layer

def rbf(self, x, center, spread):

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As there is no test file in this pull request nor any test function or class in the file neural_network/radial_basis_function_neural_network.py, please provide doctest for the function rbf

Please provide return type hint for the function: rbf. If the function does not return a value, please provide the type hint as: def function() -> None:

Please provide descriptive name for the parameter: x

Please provide type hint for the parameter: x

Please provide type hint for the parameter: center

Please provide type hint for the parameter: spread

"""Radial Basis Function (Gaussian)."""
return np.exp(-(np.linalg.norm(x - center) ** 2) / (2 * spread**2))

def forward(self, x):

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As there is no test file in this pull request nor any test function or class in the file neural_network/radial_basis_function_neural_network.py, please provide doctest for the function forward

Please provide return type hint for the function: forward. If the function does not return a value, please provide the type hint as: def function() -> None:

Please provide descriptive name for the parameter: x

Please provide type hint for the parameter: x

output = np.dot(hidden_outputs, self.weights) # Compute final output
return output

def train(self, x_train, y_train, epochs, learning_rate):

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As there is no test file in this pull request nor any test function or class in the file neural_network/radial_basis_function_neural_network.py, please provide doctest for the function train

Please provide return type hint for the function: train. If the function does not return a value, please provide the type hint as: def function() -> None:

Please provide type hint for the parameter: x_train

Please provide type hint for the parameter: y_train

Please provide type hint for the parameter: epochs

Please provide type hint for the parameter: learning_rate

# Update weights
self.weights += learning_rate * hidden_outputs.reshape(-1, 1) * error

def predict(self, x_test):

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As there is no test file in this pull request nor any test function or class in the file neural_network/radial_basis_function_neural_network.py, please provide doctest for the function predict

Please provide return type hint for the function: predict. If the function does not return a value, please provide the type hint as: def function() -> None:

Please provide type hint for the parameter: x_test

Copy link

@algorithms-keeper algorithms-keeper bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Click here to look at the relevant links ⬇️

🔗 Relevant Links

Repository:

Python:

Automated review generated by algorithms-keeper. If there's any problem regarding this review, please open an issue about it.

algorithms-keeper commands and options

algorithms-keeper actions can be triggered by commenting on this PR:

  • @algorithms-keeper review to trigger the checks for only added pull request files
  • @algorithms-keeper review-all to trigger the checks for all the pull request files, including the modified files. As we cannot post review comments on lines not part of the diff, this command will post all the messages in one comment.

NOTE: Commands are in beta and so this feature is restricted only to a member or owner of the organization.

import numpy as np

class ART1:
def __init__(self, num_features, vigilance=0.8):

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please provide return type hint for the function: __init__. If the function does not return a value, please provide the type hint as: def function() -> None:

Please provide type hint for the parameter: num_features

Please provide type hint for the parameter: vigilance

self.vigilance = vigilance
self.weights = [] # Stores the weights for clusters

def _similarity(self, x, w):

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As there is no test file in this pull request nor any test function or class in the file neural_network/adaptive_resonance_theory_1.py, please provide doctest for the function _similarity

Please provide return type hint for the function: _similarity. If the function does not return a value, please provide the type hint as: def function() -> None:

Please provide descriptive name for the parameter: x

Please provide type hint for the parameter: x

Please provide descriptive name for the parameter: w

Please provide type hint for the parameter: w

"""
return np.sum(np.minimum(x, w)) / np.sum(x)

def _weight_update(self, x, w):

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As there is no test file in this pull request nor any test function or class in the file neural_network/adaptive_resonance_theory_1.py, please provide doctest for the function _weight_update

Please provide return type hint for the function: _weight_update. If the function does not return a value, please provide the type hint as: def function() -> None:

Please provide descriptive name for the parameter: x

Please provide type hint for the parameter: x

Please provide descriptive name for the parameter: w

Please provide type hint for the parameter: w

"""
return np.minimum(x, w)

def train(self, data):

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As there is no test file in this pull request nor any test function or class in the file neural_network/adaptive_resonance_theory_1.py, please provide doctest for the function train

Please provide return type hint for the function: train. If the function does not return a value, please provide the type hint as: def function() -> None:

Please provide type hint for the parameter: data

if not assigned:
self.weights.append(x.copy())

def predict(self, x):

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As there is no test file in this pull request nor any test function or class in the file neural_network/adaptive_resonance_theory_1.py, please provide doctest for the function predict

Please provide return type hint for the function: predict. If the function does not return a value, please provide the type hint as: def function() -> None:

Please provide descriptive name for the parameter: x

Please provide type hint for the parameter: x



class RBFNN:
def __init__(self, input_size, hidden_size, output_size):

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please provide return type hint for the function: __init__. If the function does not return a value, please provide the type hint as: def function() -> None:

Please provide type hint for the parameter: input_size

Please provide type hint for the parameter: hidden_size

Please provide type hint for the parameter: output_size

(hidden_size, output_size)
) # Weights for output layer

def rbf(self, x, center, spread):

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As there is no test file in this pull request nor any test function or class in the file neural_network/radial_basis_function_neural_network.py, please provide doctest for the function rbf

Please provide return type hint for the function: rbf. If the function does not return a value, please provide the type hint as: def function() -> None:

Please provide descriptive name for the parameter: x

Please provide type hint for the parameter: x

Please provide type hint for the parameter: center

Please provide type hint for the parameter: spread

"""Radial Basis Function (Gaussian)."""
return np.exp(-(np.linalg.norm(x - center) ** 2) / (2 * spread**2))

def forward(self, x):

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As there is no test file in this pull request nor any test function or class in the file neural_network/radial_basis_function_neural_network.py, please provide doctest for the function forward

Please provide return type hint for the function: forward. If the function does not return a value, please provide the type hint as: def function() -> None:

Please provide descriptive name for the parameter: x

Please provide type hint for the parameter: x

output = np.dot(hidden_outputs, self.weights) # Compute final output
return output

def train(self, x_train, y_train, epochs, learning_rate):

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As there is no test file in this pull request nor any test function or class in the file neural_network/radial_basis_function_neural_network.py, please provide doctest for the function train

Please provide return type hint for the function: train. If the function does not return a value, please provide the type hint as: def function() -> None:

Please provide type hint for the parameter: x_train

Please provide type hint for the parameter: y_train

Please provide type hint for the parameter: epochs

Please provide type hint for the parameter: learning_rate

# Update weights
self.weights += learning_rate * hidden_outputs.reshape(-1, 1) * error

def predict(self, x_test):

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As there is no test file in this pull request nor any test function or class in the file neural_network/radial_basis_function_neural_network.py, please provide doctest for the function predict

Please provide return type hint for the function: predict. If the function does not return a value, please provide the type hint as: def function() -> None:

Please provide type hint for the parameter: x_test

@cclauss
Copy link
Member

cclauss commented Nov 1, 2024

Closing require_type_hints PRs to prepare for Hacktoberfest

@cclauss cclauss closed this Nov 1, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
awaiting reviews This PR is ready to be reviewed require descriptive names This PR needs descriptive function and/or variable names require tests Tests [doctest/unittest/pytest] are required require type hints https://docs.python.org/3/library/typing.html tests are failing Do not merge until tests pass
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants